package com.sansui.blog.controller.admin.page;

import com.sansui.blog.pojo.SysConfig;
import com.sansui.blog.service.SysInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * @name: SysSettingController
 * @author: Sansui
 * @Software: IDEA
 * @Blog: https://www.cnblogs.com/sansui6/
 * @date: 2022-04-14 21:29
 **/

// 系统管理 - 系统设置
@Controller
@RequestMapping("/admin")
public class SysSettingController {

    @Autowired
    private SysInfoService sysInfoService;

        //  系统后台-系统设置
    @GetMapping("page/setting")
    public ModelAndView adminSetting(ModelAndView mv){
        SysConfig sysConfig = sysInfoService.getSysSetting();
        mv.setViewName("admin/page/setting");
        mv.addObject("webname",sysConfig.getWebname());
        mv.addObject("weburl",sysConfig.getWeburl());
        mv.addObject("cacheTime",sysConfig.getCacheTime());
        mv.addObject("maxFiles",sysConfig.getMaxFiles());
        mv.addObject("fileType",sysConfig.getFileType());
        mv.addObject("webTitle",sysConfig.getWebTitle());
        mv.addObject("metaTips",sysConfig.getMetaTips());
        mv.addObject("metaNotes",sysConfig.getMetaNotes());
        mv.addObject("copyRightInfo",sysConfig.getCopyRightInfo());
        mv.addObject("versionNumber",sysConfig.getVersionNumber());
        mv.addObject("tongji",sysConfig.getTongji());
        return mv;
    }

    @PostMapping("page/saveSetting")
    @ResponseBody
    public Map<String, Object> saveSetting(@RequestBody SysConfig sysInfo){
        Map<String, Object> map = sysInfoService.saveSetting(sysInfo);
        return map;
    }

}
